package game.tileMap
{
	import flash.display.Sprite;
	import flash.geom.Rectangle;
	
	import mk.gamemap.model.Tile;
	import mk.gamemap.view.SpriteCache;
	
	public class TileMapCanvs extends Sprite
	{
		var tileSize:int=32;
		var data:Array;
		private var spFactory:SpriteCache;
		public var ox:int;
		public var oy:int;
		var scrollRec:Rectangle
		var maxRec:Rectangle
		public function TileMapCanvs()
		{
			super();
			spFactory=new SpriteCache();
			
			//scrollRec=new Rectangle(0,0,800,600);//显示的范围
		//	this.scrollRect=scrollRec;//确定地图的可显示范围
		}
		
		public function setData(data:Array):void{
			this.data=data;
			drawMap()
		}
		
		
		public function drawMap():void{
			//dispose();
			for(var i:int=0;i<data.length;i++){
				for(var j:int=0;j<data[0].length;j++){
					var tileId:int=data[i][j]
					var tileView:Sprite=spFactory.drawTile(tileId)
					tileView.x=i*tileSize;
					tileView.y=j*tileSize;
					this.addChild(tileView);
				}
				
			}
			
			
		}
		
		public function scrollH(distance:int):void{
			scrollRec.x-=distance;
			this.scrollRect=scrollRec;
		}
		public function scrollV(distance:int):void{
			scrollRec.y-=distance;
			this.scrollRect=scrollRec;
		}
	}
}